package controller;

import java.util.HashMap;
import android.view.SurfaceHolder;
import model.OnScreen;
import model.Snippet;
import model.camera.CameraManager;
import view.ScannerActivity;

public class SystemController {
	
	private CameraManager _cameraManager;
	
	public SystemController(ScannerActivity observer)
	{
		_cameraManager = new CameraManager();
		
		//pass the observer to the OnScreen Singleton
		OnScreen.getInstance().setObserver(observer);
	}
	
	public void startCamera(SurfaceHolder holder)
	{
		if(_cameraManager == null)
			_cameraManager = new CameraManager();
		
		_cameraManager.startPreview(holder);
	}
	
	public void stopCamera()
	{		
		if(_cameraManager != null)
			_cameraManager.release();
		_cameraManager = null;
		
		OnScreen.getInstance().resetTimer();
		OnScreen.getInstance().updateSnippetList(new HashMap<String, Snippet>());
	}

	public void resumeCamera(SurfaceHolder holder) 
	{		
		if(_cameraManager != null)
			_cameraManager.release();
		
		_cameraManager = new CameraManager();
		_cameraManager.startPreview(holder);
	}

	public void toggleFlashLight() 
	{
		if(_cameraManager != null)
			_cameraManager.toggleFlashLight();
	}

}
